package com.netty.pro.netty.nio;

import java.nio.ByteBuffer;

/**
 * @author xuzn
 * @ClassName: ReadOnlyBuffer
 * @ProjectName echo-project
 * @date 2020/3/5/11:45
 */
public class ReadOnlyBuffer {
  public static void main(String[] args) {
    ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
    for (int i = 0; i <= 3; i++) {
      byteBuffer.put((byte) i);
    }
    byteBuffer.flip();
    // 将buffer转换成只读的buffer
    ByteBuffer readOnlyBuffer = byteBuffer.asReadOnlyBuffer();
    // 读取buffer中的值
    while (readOnlyBuffer.hasRemaining()) {
      System.out.println(readOnlyBuffer.get());
    }
    readOnlyBuffer.put((byte) 10);
  }
}
